﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SysLock
{
    public partial class Lock : Form
    {
        private string picType = "1";
        private string picPath = "";

        public Lock(string type,string path)
        {
            InitializeComponent();
            picType = type;
            picPath = path;
        }

        private void Lock_Load(object sender, EventArgs e)
        {
            Size size = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
            this.Location = new Point(0, 0);
            this.Size = size;
            this.pictureBox1.Refresh();
            switch (picType)
            {
                case "0":
                    this.pictureBox1.Image = new Bitmap(picPath);
                    break;
                case "2":
                    this.pictureBox1.Image = Properties.Resources.win8;
                    break;
                default:
                    this.pictureBox1.Image = Properties.Resources.win7;
                    break;
            }
            this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        }

        private void Lock_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.timer1.Enabled = false;
                //获取任务栏
                IntPtr hTray = SafeNativeMethods.FindWindowA("Shell_TrayWnd", String.Empty);
                //显示任务栏
                SafeNativeMethods.ShowWindow(hTray, 5);
                this.Close();
            }
        }

        private void Lock_Shown(object sender, EventArgs e)
        {
            //获取任务栏
            IntPtr hTray = SafeNativeMethods.FindWindowA("Shell_TrayWnd", String.Empty);
            //隐藏任务栏
            SafeNativeMethods.ShowWindow(hTray, 0);

            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
            this.timer1.Interval = 100;
            this.timer1.Enabled = true;
        }

        private void Lock_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.F4) && (e.Alt == true))
            {
                e.Handled = true;
            }
            if ((e.KeyCode == Keys.Tab) && (e.Alt == true))
            {
                e.Handled = true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (SafeNativeMethods.SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2) == false)
            {
                this.timer1.Enabled = false;
                MessageBox.Show("窗口置顶失败");
            }
        }

        private void Lock_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
